<template lang="pug">
	.hospital-record-wrap
		div(@click="findPatient")
			field-item(text="就诊人" :showArrow="true" :option="name" hint="切换" :showBorder="false")
		.hospital-record-content
			no-item(text="暂无相关记录" v-if="noItem")
			.hospital-record-item(v-for="(item,index) in list" :key="index")
				.hospital-name
					img(src="../../assets/image/healthCard/hospitalIcon.png")
					span {{item.org_name}}
				.hospital-content
					.hospital-item
						p 患者姓名：
							span {{name}}
						p 入院时间：
							span {{item.ryrq}}
					.hospital-item
						p 住院科室：
							span {{item.ksmc}}
						p 出院时间：
							span {{item.cyrq}}
				.record-footer
					.record-button(@click="goDetail(item)") 详情
</template>
<script>
import noItem from '@/components/no-item'
import fieldItem from '@/components/field-item'
export default {
	name: 'hospitalRecord',
	data() {
		return {
			list: [],
			name: '',
			noItem: false
		}
	},
	created() {},
	mounted() {
		this.name = this.wx.getStorageSync('findPatient').name
		this.getRecord()
	},
	onShow() {
		if (this.wx.getStorageSync('isReload').reload) {
			this.list = []
			this.noItem = false
			this.name = this.wx.getStorageSync('findPatient').name
			this.wx.setStorage({
				key: 'isReload',
				data: {
					reload: false
				}
			})
			this.getRecord()
		}
	},
	methods: {
		findPatient() {
			this.$router.push({
				path: '/views/doctorRecord/findPatient'
			})
		},
		goDetail(item) {
			this.$router.push({
				path: '/views/hospitalRecord/hospitalRecordDetail',
				query: {
					orgCode: item.org_code,
					zylsh: item.zylsh
				}
			})
		},
		getRecord() {
			this.wx.showLoading({
				title: '加载中',
				icon: 'none'
			})

			let findPatient = this.wx.getStorageSync('findPatient')
			let userInfo = this.wx.getStorageSync('userInfo')

			this.api.jtApi
				.hospitalRecord({
					access_token: userInfo.accessToken,
					member_num: userInfo.memberNum,
					klx: findPatient.cardType,
					kh: findPatient.cardNumber,
					brxm: this.name,
					zjhm: findPatient.idNumber,
					zjlx: '01'
				})
				.then(data => {
					this.wx.hideLoading()
					if (data.ret_code === '0') {
						let list = this.tools.formatToArray(data.details.detail)
						this.list = list
					}
					this.noItem = this.list.length <= 0
				})
				.catch(() => {
					this.noItem = this.list.length <= 0
					this.wx.hideLoading()
				})
		}
	},
	components: {
		fieldItem,
		noItem
	}
}
</script>

<style lang="stylus">
	.hospital-record-wrap
		.hospital-record-content
			position absolute
			top 100px
			left 0
			right 0
			bottom 0
			scrollY()
			.hospital-record-item
				background-color white
				margin-top mainMargin
				padding mainPadding mainPadding 0
				.hospital-name
					display flex
					align-items center
					line-height 44px
					font-size 32px
					color #2693FF
					font-weight 500
					position relative
					& > img
						width 38px
						height 38px
						margin-right 14px
				.hospital-content
					line-height 40px
					display flex
					align-items center
					font-size 28px
					padding mainPadding 0
					position relative
					.hospital-item
						max-width 50%
						flex 1
						color blackFontColor1A
						p
							overflow hidden
							white-space nowrap
							text-overflow ellipsis
							&:last-child
								padding-top 24px
						span
							color blackFontColor66
				.record-footer
					padding mainPadding 0
					display flex
					align-items center
					justify-content flex-end
					position relative
					.record-button
						width 180px
						height 60px
						background themeColor
						font-size 26px
						color white
						border-radius 30px
						overflow hidden
						line-height 60px
						text-align center
					&:after
						content ''
						position absolute
						top 0
						left 0
						right 0
						height 2px
						border-top borderStyle
</style>
